#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/18 09:52
# @Author  : youfeng
from config.user_conf import TestConfig


class CheckAuth(object):
    # 校验成功
    CODE_SUCCESS = 0

    # 没有当前用户
    CODE_NO_USER = -1

    # APP_KEY 错误
    CODE_APP_KEY_ERROR = -2

    ERROR_CODE_MSG = {
        CODE_SUCCESS: "校验成功",
        CODE_NO_USER: "用户不存在",
        CODE_APP_KEY_ERROR: "app_key不正确",
    }

    @staticmethod
    def check_user(user, app_key):
        if user != TestConfig.USERNAME:
            return CheckAuth.CODE_NO_USER

        if app_key != TestConfig.APP_KEY:
            return CheckAuth.CODE_APP_KEY_ERROR

        return CheckAuth.CODE_SUCCESS

    @classmethod
    def get_error_msg(cls, code):
        if code not in cls.ERROR_CODE_MSG:
            return "权限校验异常"

        return cls.ERROR_CODE_MSG[code]
